<template>
  <!-- 下拉框显示的方式trigger为click时是点击才显示 -->
  <el-dropdown trigger="click" @command="changeLanguage">
    <div>
      <svg-icon style="color:#fff;font-size:20px" icon-class="language" />
    </div>
    <el-dropdown-menu slot="dropdown">
      <el-dropdown-item command="zh" :disabled="'zh'=== $i18n.locale ">中文</el-dropdown-item>
      <el-dropdown-item command="en" :disabled="'en'=== $i18n.locale ">en</el-dropdown-item>
    </el-dropdown-menu>
  </el-dropdown>
</template>

<script>
import Cookie from 'js-cookie'
export default {

  methods: {
    changeLanguage(type) {
      // 将类型保存起来方便再次打开时还是原来的类型
      Cookie.set('language', type)
      //   取到i18n中的locale 也就是类型改变类型就能改变语言的切换
      this.$i18n.locale = type
      this.$message.success('切换语言成功')
    }
  }
}
</script>

<style>

</style>
